<script type="text/javascript" src="./jquery.js"></script>
CASE :<br />
1	libre = 1 / occupe = 0<br />
2	pion j1 = 1<br />
3	pion j2 = 1<br />
4	sur un rebord = 0<br />
<div id="tableau"></div>
<input type="button" onclick="generate();" value="generate"/>
<br />
<textarea id="cpp"></textarea>
<script>
    var type = 3;
    function init() {
        var i = 0;
        while (i < 19) {
            var j = 0;
            while (j < 19) {
                $('#tableau').append('<input type="text" size="1" id="' + i + '-' + j + '">');
                j++;
            }
            $('#tableau').append('<br />');
            i++;
        }
    }
    function generate() {
        var result1 = '';
        var result2 = '';
        var current = 0;
        var i = 0;
        var line = false;
        var eof = '0';
        var newline = true;
        while (i < 19) {
            var j = 0;
            newline = true;
            while (j < 19) {
                if ($('#' + i + '-' + j).attr('value') == '') {
                    if (line == true) {
                        result1 += '0000';
                        result2 += '0000';
                    }
                }
                else
                    line = true;
                if (j == 18 || newline == true)
                    eof = '0';
                else
                    eof = '1';
                if ($('#' + i + '-' + j).attr('value') == '0') {
                    result1 += '100' + eof;
                    result2 += '100' + eof;
                    newline = false;
                }
                else if ($('#' + i + '-' + j).attr('value') == '1') {
                    result1 += '010' + eof;
                    result2 += '001' + eof;
                    newline = false;
                }
                else if ($('#' + i + '-' + j).attr('value') == '2') {
                    result1 += '001' + eof;
                    result2 += '010' + eof;
                    newline = false;
                }
                else if ($('#' + i + '-' + j).attr('value') == 'X' || $('#' + i + '-' + j).attr('value') == 'x') {
                    current = (18 - i) * 76 + (18 - j) * 4;
                    result1 += '100' + eof;
                    result2 += '100' + eof;
                    newline = false;
                }
                j++;
            }
            i++;
        }
        $('#cpp').append('this->maskDouble3J1[i] = std::bitset<1083>(std::string("' + result1 + '"));\nthis->maskDouble3J2[i] = std::bitset<1083>(std::string("' + result2 + '"));\nthis->maskDouble3Offset[i++] = ' + current + ';\n');
    }
    var tab = new Array('1', '1', '0', '0', 'x');
    var resultat = new Array();
    function double3() {
        var un = 0;
        var zero = 0;
        var x = 0;
        var i = 0;
        while (i < 5) {
            var j = 0;
            while (j < 5) {
                var k = 0;
                while (k < 5) {
                    var l = 0;
                    while (l < 5) {
                        var m = 0;
                        while (m < 5) {
                            un = 0;
                            zero = 0;
                            x = 0;
                            if (tab[i] == '1')
                                un++;
                            if (tab[j] == '1')
                                un++;
                            if (tab[k] == '1')
                                un++;
                            if (tab[l] == '1')
                                un++;
                            if (tab[m] == '1')
                                un++;
                            if (un == 2) {

                                if (tab[i] == '0')
                                    zero++;
                                if (tab[j] == '0')
                                    zero++;
                                if (tab[k] == '0')
                                    zero++;
                                if (tab[l] == '0')
                                    zero++;
                                if (tab[m] == '0')
                                    zero++;
                                if (zero == 2) {
                                    var n = 0;
                                    while (n < resultat.length) {
                                        if (resultat[n] == tab[i] + tab[j] + tab[k] + tab[l] + tab[m])
                                            break;
                                        n++;
                                    }
                                    if (n == resultat.length)
                                        resultat.push(tab[i] + tab[j] + tab[k] + tab[l] + tab[m]);
                                }
                            }
                            m++;
                        }
                        l++;
                    }
                    k++;
                }
                j++;
            }
            i++;
        }
        i = 0;
        var nbr = 0;
        while (i < 30) {
            j = 0;
            while (j < 30) {
                k = 0;
                while (k < 5) {
                    l = 0;
                    while (l < 5) {
                        if (resultat[i][k] == 'x' && resultat[i][k] == resultat[j][l]) {
                            makeTab(resultat[i], k, resultat[j], l);
                            nbr++;
                        }
                        l++;
                    }
                    k++;
                }
                j++;
            }
            i++;
        }
        alert(nbr);
    }
    function makeTab(word1, len1, word2, len2) {
        if (type == 0) {
            var i = 14;
            var j = 14;
            while (i < 19) {
                j = 14;
                while (j < 19) {
                    $('#' + i + '-' + j).attr('value', '');
                    j++;
                }
                i++;
            }
            i = 0;
            while (i < 5) {
                j = 0;
                while (j < 5) {
                    if (j == len2)
                        $('#' + (18 - j) + '-' + (18 - i)).attr('value', word1[i]);
                    else if (i == len1)
                        $('#' + (18 - j) + '-' + (18 - i)).attr('value', word2[j]);
                    j++;
                }
                i++;
            }
            generate();
        }
        else if (type == 1) {
            var i = 0;
            var j = 0;
            while (i < 19) {
                j = 0;
                while (j < 19) {
                    $('#' + i + '-' + j).attr('value', '');
                    j++;
                }
                i++;
            }
            i = 0;
            var dec2 = 4 - len2;
            var dec1 = 4 - len1;
            while (i < 5) {
                j = 0;
                while (j < 5) {
                    if (j == len2)
                        $('#' + (18 - i - dec1) + '-' + (18 - i)).attr('value', word1[i]);
                    else if (i == len1)
                        $('#' + (18 - j - dec2) + '-' + (18 - i)).attr('value', word2[j]);
                    j++;
                }
                i++;
            }
            generate();
        }
        else if (type == 2) {
            var i = 0;
            var j = 0;
            while (i < 19) {
                j = 0;
                while (j < 19) {
                    $('#' + i + '-' + j).attr('value', '');
                    j++;
                }
                i++;
            }
            i = 0;
            var dec2 = 4 - len2;
            var dec1 = 4 - len1;
            var ecart = 4 - len2 - len1;
            if (ecart < 0)
                ecart = 0;
            while (i < 5) {
                j = 0;
                while (j < 5) {
                    if (j == len2)
                        $('#' + (18 - j + i - j - dec2 + dec1 - ecart) + '-' + (18 - i)).attr('value', word1[i]);
                    else if (i == len1)
                        $('#' + (18 - j - ecart) + '-' + (18 - i)).attr('value', word2[j]);
                    j++;
                }
                i++;
            }
            generate();
        }
        else if (type == 3) {
            var i = 0;
            var j = 0;
            while (i < 19) {
                j = 0;
                while (j < 19) {
                    $('#' + i + '-' + j).attr('value', '');
                    j++;
                }
                i++;
            }
            i = 0;
            var dec1 = 0;
            var dec2 = 0;
            var dec3 = 0;
            var ecart = len2 - len1;
            if (len1 + len2 < 4)
                dec3 = 4 - (len1 + len2);
            if (ecart > 0)
                dec2 = ecart;
            else if (ecart < 0)
                dec1 = ecart;
            while (i < 5) {
                j = 0;
                while (j < 5) {
                    if (j == len2)
                        $('#' + (18 - i - dec2) + '-' + (18 - i - dec3)).attr('value', word1[i]);
                    else if (i == len1)
                        $('#' + (18 - j + dec1) + '-' + (18 - i - i + j - dec1 - dec2 - dec3)).attr('value', word2[j]);
                    j++;
                }
                i++;
            }
            generate();
        }
    }
    init();
    double3();
</script>